import { createRouter, createWebHistory } from 'vue-router'; // 引入 Vue Router 的 API
import Home from '@/views/Home.vue';
import Test from "@/views/Test.vue";
import Manager from "@/views/Manager.vue";
import notfound from "@/views/notfound.vue";
import Data from "@/views/Data.vue";
import Racer from "@/views/racer.vue";
import adjusticator from "@/views/adjusticator.vue";
import eventInformation from "@/views/eventInformation.vue";
import eventApply from "@/views/eventApply.vue";
import eventCategory from "@/views/eventCategory.vue";
import login from "@/views/login.vue";
import CompetitionIndex from "@/views/CompetitionIndex.vue";
import adjustIndex from "@/views/adjustIndex.vue";
import participantIndex from "@/views/participantIndex.vue";
import registerIndex from "@/views/registerIndex.vue";
import EventCategoryRelation from "@/views/EventCategoryRelation.vue";
import file from "@/views/file.vue"; // 确保路径正确
import notice from '@/views/notice.vue'; // 确保路径正确
import participantEventPage from '@/views/participantEventPage.vue'; // 确保路径正确
import eventApplyCompete from '@/views/eventApplyCompete.vue'; // 确保路径正确
import DataCompete from '@/views/DataCompete.vue'; // 确保路径正确
import noticeCompete from '@/views/noticeCompete.vue'; // 确保路径正确
import fileCompete from '@/views/fileCompete.vue'; // 确保路径正确


const routes = [
  { path: '/', redirect: '/login', component: login },

  {
    path: '/Manager', name: 'Manager', component: Manager, children: [
      { path: 'home', name: 'Home', meta: { title: '主页' }, component: Home },
      { path: 'Test', name: 'Test', meta: { title: '测试' }, component: Test },
      { path: 'Data', name: 'data', meta: { title: '数据' }, component: Data },
      { path: 'racer', name: 'racer', meta: { title: '参赛者' }, component: Racer },
      { path: 'adjusticator', name: 'adjusticator', meta: { title: '评委' }, component: adjusticator },
      { path: 'eventInformation', name: 'eventInformation', meta: { title: '赛事信息' }, component: eventInformation },
      { path: 'eventApply', name: 'eventApply', meta: { title: '赛事报名情况' }, component: eventApply },
      { path: 'eventCategory', name: 'eventCategory', meta: { title: '赛事类别' }, component: eventCategory },
      { path: 'notice', name: 'notice', meta: { title: '赛事公告' }, component: notice },
      { path: 'file', name: 'file', meta: { title: '赛事文件' }, component: file },
      { path: 'EventCategoryRelation', name: 'EventCategoryRelation', meta: { title: '赛事关联' }, component: EventCategoryRelation },
    ]
  },

  {
    path: '/adjustIndex', name: 'adjustIndex', component: adjustIndex, children: [
      { path: 'eventInformation', name: 'adeventInformation', meta: { title: '赛事信息' }, component: eventInformation },
      { path: 'eventApply', name: 'adeventApply', meta: { title: '赛事报名情况' }, component: eventApply },
      { path: 'Data', name: 'addata', meta: { title: '数据' }, component: Data },
      { path: 'notice', name: 'adnotice', meta: { title: '赛事公告' }, component: notice },
      { path: 'file', name: 'adfile', meta: { title: '赛事文件' }, component: file },

    ]
  },

  {
    path: '/participantIndex', name: 'participantIndex', component: participantIndex, children: [
      { path: 'participantEventPage', name: 'participantEventPage', meta: { title: '赛事信息' }, component: participantEventPage },
      { path: 'eventApplyCompete', name: 'eventApplyCompete', meta: { title: '赛事报名情况' }, component: eventApplyCompete },
      { path: 'DataCompete', name: 'DataCompete', meta: { title: '数据' }, component: DataCompete },
      { path: 'noticeCompete', name: 'noticeCompete', meta: { title: '赛事公告' }, component: noticeCompete },
      { path: 'fileCompete', name: 'fileCompete', meta: { title: '赛事文件' }, component: fileCompete },
    ]
  },

  // 其他路由
  { path: '/notfound', name: 'Notfound', meta: { title: '404找不到页面' }, component: notfound },
  { path: '/login', name: 'login', meta: { title: '登录' }, component: login },
  { path: '/registerIndex', name: 'register', meta: { title: '注册' }, component: registerIndex },
  { path: '/CompetitionIndex', name: 'CompetitionIndex', meta: { title: '赛事平台' }, component: CompetitionIndex },
  //{path: '/adjustIndex', name: 'adjustIndex', meta: {title: '评审平台'}, component: adjustIndex},

  // { path: '/Notice', name: 'Notice', meta: { title: '公告' }, component: Notice },

  { path: '/:pathMatch(.*)', redirect: '/notfound' }
];

const router = createRouter({
  history: createWebHistory(), // 使用 history 模式
  routes
});

router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  next();
})


export default router;
